$(function () {
    var nc_token = ["CF_APP_1", (new Date()).getTime(), Math.random()].join(':');
    var yzflag
    var NC_Opt = {
        renderTo: "#your-dom-id",
        appkey: "CF_APP_1",
        scene: "register",
        token: nc_token,
        customWidth: 300,
        trans: {
            "key1": "code0"
        },
        elementID: ["usernameID"],
        is_Opt: 0,
        language: "cn",
        isEnabled: true,
        timeout: 3000,
        times: 5,
        apimap: {
            // 'analyze': '//a.com/nocaptcha/analyze.jsonp',
            // 'get_captcha': '//b.com/get_captcha/ver3',
            // 'get_captcha': '//pin3.aliyun.com/get_captcha/ver3'
            // 'get_img': '//c.com/get_img',
            // 'checkcode': '//d.com/captcha/checkcode.jsonp',
            // 'umid_Url': '//e.com/security/umscript/3.2.1/um.js',
            // 'uab_Url': '//aeu.alicdn.com/js/uac/909.js',
            // 'umid_serUrl': 'https://g.com/service/um.json'
        },
        callback: function (data) {
            yzflag = true
            if ($('#login_mail').val() != '' && $('#login_password').val() != '') {
                $('#login_btn').removeAttr("disabled");
                $('#login_btn').css({
                    'background': '#00A862',
                    'border': '0',
                    'color': '#fff',
                    'cursor': 'pointer'
                })
            } else {
                $('#login_btn').css({
                    'background': '#f7f7f7',
                    'border -color': '#f7f7f7',
                    'color': 'rgba(0, 0, 0, 0.38)',
                    'cursor': 'not-allowed'
                })
                $('#login_btn').attr("disabled", "disabled");
            }


        }
    }
    var nc = new noCaptcha(NC_Opt)

    nc.upLang('cn', {
        _startTEXT: "请按住滑块，拖动到最右边",
        _yesTEXT: "验证通过",
        _error300: "哎呀，出错了，点击<a href=\"javascript:__nc.reset()\">刷新</a>再来一次",
        _errorNetwork: "网络不给力，请<a href=\"javascript:__nc.reset()\">点击刷新</a>",
    })
    $('.inputss input').each(function (index, i) {
        $(i).bind("input propertychange", function () {
            if ($('#login_mail').val() != '' && $('#login_password').val() != '' && yzflag == true) {
                $('#login_btn').removeAttr("disabled");
                $('#login_btn').css({
                    'background': '#00A862',
                    'border': '0',
                    'color': '#fff',
                    'cursor': 'pointer'
                })
            } else {
                $('#login_btn').css({
                    'background': '#f7f7f7',
                    'border -color': '#f7f7f7',
                    'color': 'rgba(0, 0, 0, 0.38)',
                    'cursor': 'not-allowed'
                })
                $('#login_btn').attr("disabled", "disabled");
            }

        })
    })
    $('#login_btn').click(function () {
        console.log(1);
        var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
        if (reg.test($('#login_mail').val())) {
            console.log('发送登录请求');
            $.ajax({
                method: "post",
                url: "/login",
                data: {
                    mail: $("#login_mail").val(),
                    password: $("#login_password").val()
                },
                success: function (data) {
                    alert(data.msg)
                    if (data.code == 200) {
                        location.href = '/'
                    }
                },
                fail: function (err) {
                    console.log(err);
                }
            })
        } else {
            alert("邮箱格式不正确");
        }

    })
})